.class public final Lcom/burstly/lib/component/AdaptorFactoryCache;
.super Ljava/lang/Object;
.source "AdaptorFactoryCache.java"


# static fields
.field private static final FACTORY_CACHE:Ljava/util/Map; = null
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Lcom/burstly/lib/feature/networks/IAdaptorFactory;",
            ">;"
        }
    .end annotation
.end field

.field private static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final TAG:Ljava/lang/String; = "AdaptorFactoryCache"


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 39
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    .line 44
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    sput-object v0, Lcom/burstly/lib/component/AdaptorFactoryCache;->FACTORY_CACHE:Ljava/util/Map;

    return-void
.end method

.method private constructor <init>()V
    .locals 0

    .prologue
    .line 54
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 55
    return-void
.end method

.method public static cacheFactory(Ljava/lang/String;Lcom/burstly/lib/feature/networks/IAdaptorFactory;)V
    .locals 1
    .parameter "factoryClassName"
    .parameter "factory"

    .prologue
    .line 158
    sget-object v0, Lcom/burstly/lib/component/AdaptorFactoryCache;->FACTORY_CACHE:Ljava/util/Map;

    invoke-interface {v0, p0, p1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 159
    return-void
.end method

.method private static createFactory(Ljava/lang/String;Ljava/util/Map;)Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    .locals 10
    .parameter "factoryClassName"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "*>;)",
            "Lcom/burstly/lib/feature/networks/IAdaptorFactory;"
        }
    .end annotation

    .prologue
    .local p1, params:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;*>;"
    const/4 v8, 0x1

    const/4 v9, 0x0

    .line 115
    :try_start_0
    sget-object v5, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v6, "Creating factory for {0} ..."

    const/4 v7, 0x0

    new-array v7, v7, [Ljava/lang/Object;

    invoke-virtual {v5, v6, p0, v7}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 116
    invoke-static {p0}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v0

    .line 117
    .local v0, clz:Ljava/lang/Class;,"Ljava/lang/Class<*>;"
    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Class;

    invoke-virtual {v0, v5}, Ljava/lang/Class;->getDeclaredConstructor([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;

    move-result-object v1

    .line 118
    .local v1, constructor:Ljava/lang/reflect/Constructor;,"Ljava/lang/reflect/Constructor<*>;"
    const/4 v5, 0x1

    invoke-virtual {v1, v5}, Ljava/lang/reflect/Constructor;->setAccessible(Z)V

    .line 119
    const/4 v5, 0x0

    new-array v5, v5, [Ljava/lang/Object;

    invoke-virtual {v1, v5}, Ljava/lang/reflect/Constructor;->newInstance([Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    :try_end_0
    .catch Ljava/lang/ClassNotFoundException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    .line 130
    .end local v0           #clz:Ljava/lang/Class;,"Ljava/lang/Class<*>;"
    .end local v1           #constructor:Ljava/lang/reflect/Constructor;,"Ljava/lang/reflect/Constructor<*>;"
    :goto_0
    return-object v3

    .line 123
    :catch_0
    move-exception v4

    .line 124
    .local v4, nfe:Ljava/lang/ClassNotFoundException;
    sget-object v5, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v6, "AdaptorFactoryCache"

    const-string v7, "Unsupported network: {0}"

    new-array v8, v8, [Ljava/lang/Object;

    aput-object p0, v8, v9

    invoke-virtual {v5, v6, v7, v8}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 130
    .end local v4           #nfe:Ljava/lang/ClassNotFoundException;
    :goto_1
    const/4 v3, 0x0

    goto :goto_0

    .line 126
    :catch_1
    move-exception v2

    .line 127
    .local v2, e:Ljava/lang/Exception;
    sget-object v5, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v6, "AdaptorFactoryCache"

    const-string v7, "Could not instantiate factory class {0} for \'\'{0}\'\'"

    new-array v8, v8, [Ljava/lang/Object;

    aput-object p0, v8, v9

    invoke-virtual {v5, v6, v7, v8}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 128
    sget-object v5, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v6, "AdaptorFactoryCache"

    invoke-static {v2}, Landroid/util/Log;->getStackTraceString(Ljava/lang/Throwable;)Ljava/lang/String;

    move-result-object v7

    new-array v8, v9, [Ljava/lang/Object;

    invoke-virtual {v5, v6, v7, v8}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1
.end method

.method public static declared-synchronized destroy()V
    .locals 10

    .prologue
    .line 138
    const-class v4, Lcom/burstly/lib/component/AdaptorFactoryCache;

    monitor-enter v4

    :try_start_0
    sget-object v3, Lcom/burstly/lib/component/AdaptorFactoryCache;->FACTORY_CACHE:Ljava/util/Map;

    invoke-interface {v3}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v3

    invoke-interface {v3}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v2

    .local v2, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v2}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_0

    invoke-interface {v2}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljava/util/Map$Entry;

    .line 139
    .local v0, entry:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Lcom/burstly/lib/feature/networks/IAdaptorFactory;>;"
    sget-object v3, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v5, "AdaptorFactoryCache"

    const-string v6, "Destroying {0} factory"

    const/4 v7, 0x1

    new-array v7, v7, [Ljava/lang/Object;

    const/4 v8, 0x0

    invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v9

    aput-object v9, v7, v8

    invoke-virtual {v3, v5, v6, v7}, Lcom/burstly/lib/util/LoggerExt;->logInfo(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 140
    invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Lcom/burstly/lib/feature/networks/IAdaptorFactory;

    invoke-interface {v3}, Lcom/burstly/lib/feature/networks/IAdaptorFactory;->destroy()V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_1
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 143
    .end local v0           #entry:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Lcom/burstly/lib/feature/networks/IAdaptorFactory;>;"
    :catch_0
    move-exception v1

    .line 144
    .local v1, exception:Ljava/lang/Exception;
    :try_start_1
    sget-object v3, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v5, "AdaptorFactoryCache"

    invoke-virtual {v3, v5, v1}, Lcom/burstly/lib/util/LoggerExt;->logThrowable(Ljava/lang/String;Ljava/lang/Throwable;)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1

    .line 147
    :try_start_2
    sget-object v3, Lcom/burstly/lib/component/AdaptorFactoryCache;->FACTORY_CACHE:Ljava/util/Map;

    invoke-interface {v3}, Ljava/util/Map;->clear()V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 149
    .end local v1           #exception:Ljava/lang/Exception;
    :goto_1
    monitor-exit v4

    return-void

    .line 147
    :cond_0
    :try_start_3
    sget-object v3, Lcom/burstly/lib/component/AdaptorFactoryCache;->FACTORY_CACHE:Ljava/util/Map;

    invoke-interface {v3}, Ljava/util/Map;->clear()V
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    goto :goto_1

    .line 138
    :catchall_0
    move-exception v3

    monitor-exit v4

    throw v3

    .line 147
    :catchall_1
    move-exception v3

    :try_start_4
    sget-object v5, Lcom/burstly/lib/component/AdaptorFactoryCache;->FACTORY_CACHE:Ljava/util/Map;

    invoke-interface {v5}, Ljava/util/Map;->clear()V

    throw v3
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_0
.end method

.method public static declared-synchronized getFactory(Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    .locals 8
    .parameter "factoryClassName"
    .parameter "networkName"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "Ljava/lang/String;",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "*>;)",
            "Lcom/burstly/lib/feature/networks/IAdaptorFactory;"
        }
    .end annotation

    .prologue
    .line 69
    .local p2, params:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;*>;"
    const-class v3, Lcom/burstly/lib/component/AdaptorFactoryCache;

    monitor-enter v3

    :try_start_0
    sget-object v2, Lcom/burstly/lib/component/AdaptorFactoryCache;->FACTORY_CACHE:Ljava/util/Map;

    invoke-interface {v2, p0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/burstly/lib/feature/networks/IAdaptorFactory;

    .line 70
    .local v0, factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    if-nez v0, :cond_0

    .line 72
    invoke-static {p1}, Lcom/burstly/lib/feature/FeatureFactory;->getAdaptorFactoryFeature(Ljava/lang/String;)Lcom/burstly/lib/feature/networks/IAdaptorFactory;

    move-result-object v0

    .line 73
    if-nez v0, :cond_2

    .line 74
    sget-object v2, Lcom/burstly/lib/component/AdaptorFactoryCache;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v4, "AdaptorFactoryCache"

    const-string v5, "No {0} factory in config.xml. Trying to load using classpath..."

    const/4 v6, 0x1

    new-array v6, v6, [Ljava/lang/Object;

    const/4 v7, 0x0

    aput-object p0, v6, v7

    invoke-virtual {v2, v4, v5, v6}, Lcom/burstly/lib/util/LoggerExt;->logInfo(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 76
    invoke-static {p0, p2}, Lcom/burstly/lib/component/AdaptorFactoryCache;->createFactory(Ljava/lang/String;Ljava/util/Map;)Lcom/burstly/lib/feature/networks/IAdaptorFactory;

    move-result-object v0

    move-object v1, v0

    .line 78
    .end local v0           #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    .local v1, factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    :goto_0
    if-eqz v1, :cond_1

    .line 79
    new-instance v0, Lcom/burstly/lib/component/AdaptorFactoryWrapper;

    invoke-direct {v0, v1}, Lcom/burstly/lib/component/AdaptorFactoryWrapper;-><init>(Lcom/burstly/lib/feature/networks/IAdaptorFactory;)V

    .line 80
    .end local v1           #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    .restart local v0       #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    invoke-static {p0, v0}, Lcom/burstly/lib/component/AdaptorFactoryCache;->cacheFactory(Ljava/lang/String;Lcom/burstly/lib/feature/networks/IAdaptorFactory;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 83
    :cond_0
    :goto_1
    monitor-exit v3

    return-object v0

    .line 69
    .end local v0           #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    :catchall_0
    move-exception v2

    monitor-exit v3

    throw v2

    .restart local v1       #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    :cond_1
    move-object v0, v1

    .end local v1           #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    .restart local v0       #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    goto :goto_1

    :cond_2
    move-object v1, v0

    .end local v0           #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    .restart local v1       #factory:Lcom/burstly/lib/feature/networks/IAdaptorFactory;
    goto :goto_0
.end method
